package com.qf;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.dao.CarMapper;
import com.qf.dao.CityMapper;
import com.qf.dao.OrderMapper;
import com.qf.dao.UserMapper;
import com.qf.pojo.*;
import com.qf.service.CarService;
import com.qf.service.CityService;
import com.qf.service.OrderService;
import com.qf.vo.BaseResult;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.servlet.http.HttpSession;
import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:spring-context.xml")
public class test_login {

    @Autowired
    UserMapper userMapper;

    @Autowired
    CityMapper cityMapper;

    @Autowired
    CityService cityService;

    @Autowired
    CarService carService;

    @Autowired
    CarMapper carMapper;

    @Autowired
    OrderService orderService;


    @Test
    public void test() {
        User user = userMapper.findUserByTel("123456");
        System.out.println(user);
    }

    @Test
    public void testAdd() {
        User user = new User();
        user.setTel("666666");
        user.setCode("6666");
        user.setEmail("6666@qq.com");
        user.setPassword("666666");
        userMapper.insertUser(user);
    }

    @Test
    public void findAllCityTest() {
        List<City> allCity = cityMapper.findAllCity(0);
        System.out.println(allCity);
        BaseResult baseResult = cityService.findAllCity(0);
        System.out.println(baseResult);
    }

    @Test
    public void findAllByPrice() {
        List<Car> allByPrice = carMapper.findAllByPrice();
        System.out.println(allByPrice);
    }

    @Test
    public void findAllByHot() {
        List<Car> allByHot = carMapper.findAllByHot();
        System.out.println(allByHot);
    }

//    @Test
//    public void viewCityTest(){
//        BaseResult baseResult = cityService.viewCity(1);
//        System.out.println(baseResult);
//    }

    @Test
    public void viewCityTest() {
        BaseResult baseResult = cityService.viewCity(10, 8);
        System.out.println(baseResult);
    }

    @Test
    public void findCarTest() {
//        Car carById = carMapper.findCarById(1);
//        System.out.println(carById);
        BaseResult carById = carService.findCarById(1);
        System.out.println(carById);

    }


    @Autowired
    OrderMapper orderMapper;

    @Test
    public void addOrderTest() {
        Order order = new Order();
        order.setBackid(7);
        order.setCid(1);
        order.setGetid(7);
        order.setOprice(189);
        order.setStatus("已预订");
        order.setUid(1);
        orderMapper.insertOrder(order);
    }

    @Test
    public void findAllTest() {
        List<Order> all = orderMapper.findAll();
        System.out.println(all);
    }

    @Test
    public void findMyOrderTest() {
        User userByTel = userMapper.findUserByTel("13783018934");
        List<Order> myOrder = orderMapper.findMyOrder(userByTel);
        System.out.println(myOrder);
    }


    @Test
    public void findCityByPidTest() {
        City cityByPid = cityMapper.findCityByPid(2);
        System.out.println(cityByPid);
    }

    @Test
    public void orderViewTest() {
        User user = userMapper.findUserByTel("666666");
        List<OrderView> list = orderMapper.viewOrder(user);
        System.out.println(list);
    }

    @Test
    public void delTest() {
        orderMapper.delOrder(38);
    }

    @Test
    public void findTest() {
        Order orderById = orderMapper.findOrderById(37);
        System.out.println(orderById);
    }

    @Test
    public void updateTelTest() {
        User user = new User();
        user.setTel("13060361806");
        user.setId(10);
        userMapper.updateTel(user);
        User userByTel = userMapper.findUserByTel("13060361806");
        System.out.println(userByTel);
    }

    @Test
    public void updateEmailTest() {
        User user = new User();
        user.setEmail("123789@qq.com");
        user.setId(8);
        userMapper.updateEmail(user);
        User userByTel = userMapper.findUserByTel("666666");
        System.out.println(userByTel);
    }

    @Test
    public void updatePasswordTest() {
        User user = new User();
        user.setPassword("123456");
        user.setId(8);
        userMapper.updatePassword(user);
        User userByTel = userMapper.findUserByTel("666666");
        System.out.println(userByTel);
    }

}
